package test;

import entity.Students;
import mapper.StudentMapper;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;

public class test01 implements StudentMapper {
    private SqlSession sqlSession;
    private StudentMapper studentMapper;

    public test01() {
        String resource = "mapper.config.xml";
        InputStream inputStream = null;
        try {
            inputStream = Resources.getResourceAsStream(resource);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
        sqlSession = sqlSessionFactory.openSession(true);
        studentMapper = sqlSession.getMapper(StudentMapper.class);
    }

    @Override
    public Students getStudentById(int id) {
        return studentMapper.getStudentById(id);
    }

    public static void main(String[] args) {
      /*  Students students01 = new Students();
        students01.setId(11);
        students01.setAge(22);
        students01.setName("33");
        test01 t1 = new test01();
       t1.insertStudent(students01);*/
       test01 t2 = new test01();
       Students students02 = t2.getStudentById(6);
       System.out.println(students02.getName());
    }

    @Override
    public int insertStudent(Students student) {
        //System.out.println("44");
        return studentMapper.insertStudent(student);
    }

    @Override
    public int updateStudent(Students student) {
        return studentMapper.updateStudent(student);
    }

    @Override
    public int deleteStudent(int id) {
        return studentMapper.deleteStudent(id);
    }
}